package cn.sc.summer.auth.handler;

import cn.sc.summer.constant.token.TokenConstant;
import cn.sc.summer.token.encrypt.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author a-xin
 * @description 登出逻辑处理
 * @belongsProject SummerCloud
 * @belongsPackage cn.sc.summer.security.handler
 * @date 2025-02-26  10:35
 */
@Slf4j
public class LogoutHandlerX implements LogoutHandler {

    /**
     * Causes a logout to be completed. The method must complete successfully.
     *
     * @param request        the HTTP request
     * @param response       the HTTP response
     * @param authentication the current principal details
     */
    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        String token = request.getHeader(TokenConstant.ACCESS_TOKEN);
        TokenUtil.deleteSimpleToken(token);
    }

}
